package PengendaliSuratDokumen;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

public class PengendaliSuratDokumen {

    public static void tambahSurat(String nomor, String prihal, String asal, String penerima, String ruangan,
            String lemari, String loker, String petugasPenerima, String tanggl) {
        KoneksiOracle koneksiOracle = new KoneksiOracle();
        koneksiOracle.getDBConnection();
        Connection conn = koneksiOracle.conn;
        try {
            java.sql.Statement statement = conn.createStatement();
            String sql = "insert into SURAT (NO_SURAT, PERIHAL ,ASAL, PENERIMA , RUANG, LEMARI, LOKER, NAMA_PETUGAS, TANGGAL_TERIMA) values ('"
                    + nomor + "','"
                    + prihal + "','"
                    + asal + "','"
                    + penerima + "','"
                    + ruangan + "','"
                    + lemari + "','"
                    + loker + "','"
                    + petugasPenerima + "','"
                    + tanggl + "')";
            statement.executeUpdate(sql);
            conn.close();
            JOptionPane.showMessageDialog(null, "Surat Berhsil Di Simpan");
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "EROR!\n"
                    + "Cek kembali:\n"
                    + "Silahkan coba kembali atau tutup program."
                    + ex.getMessage());
        }
    }

    public static void tambahDokumen(String nomor, String perihal,
            String asal, String penerima, String ruangan, String lemari, String loker, String petugasPenerima, String tanggl) {
        KoneksiOracle koneksiOracle = new KoneksiOracle();
        koneksiOracle.getDBConnection();
        Connection conn = koneksiOracle.conn;
        try {
            java.sql.Statement statement = conn.createStatement();
            String sql = "insert into DOKUMEN (NO_DOKUMEN, PERIHAL, ASAL,PENERIMA, RUANG ,LEMARI ,LOKER , NAMA_PETUGAS ,TANGGAL_TERIMA) values ('"
                    + nomor + "','"
                    + perihal + "','"
                    + asal + "','"
                    + penerima + "','"
                    + ruangan + "','"
                    + lemari + "','"
                    + loker + "','"
                    + petugasPenerima + "','"
                    + tanggl + "')";
            statement.executeUpdate(sql);
            conn.close();
            JOptionPane.showMessageDialog(null, "Dkumen Berhaasil di simpan");
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "EROR!\n"
                    + "Cek kembali:\n"
                    + "1.Format tanggal: DD MON YYYY\n"
                    + "Silahkan coba kembali atau tutup program.");
        }
    }

    public static void konfirmasiSuratUser(String nomor) {
        KoneksiOracle koneksiOracle = new KoneksiOracle();
        koneksiOracle.getDBConnection();
        Connection conn = koneksiOracle.conn;
        try {
            java.sql.Statement statement = conn.createStatement();
            String sql = "update surat "
                    + "set STATUS = 'DITERIMA' "
                    + "where (NO_SURAT = " + nomor + ")";
            statement.executeUpdate(sql);
            conn.close();
            JOptionPane.showMessageDialog(null, "Surat telah diTerima");
        } catch (SQLException ex) {
            Logger.getLogger(PengendaliSuratDokumen.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void konfirmasiDokumenUser(String nomor) {
        KoneksiOracle koneksiOracle = new KoneksiOracle();
        koneksiOracle.getDBConnection();
        Connection conn = koneksiOracle.conn;

        try {
            java.sql.Statement statement = conn.createStatement();
            String sql = "update dokumen "
                    + "set STATUS = 'DITERIMA' "
                    + "where (NO_DOKUMEN = " + nomor + ")";
            statement.executeUpdate(sql);
            conn.close();
            JOptionPane.showMessageDialog(null, "Dokumen telah diTerima");
        } catch (SQLException ex) {
            Logger.getLogger(PengendaliSuratDokumen.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}